
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
	<meta content="yes" name="apple-mobile-web-app-capable" />
	<meta content="black" name="apple-mobile-web-app-status-bar-style" />
	<meta content="telephone=no" name="format-detection" />
    <link rel="stylesheet" href="../addSelect/css/ydui.css?rev=@@hash"/>
	<link href="../begin/css/style.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" type="text/css" href="../jeDate/jeDate/skin/jedate.css"/>
	<script src="src/js/jquery.js"></script>
	<script src="../jeDate/jeDate/dist/jedate.min.js"></script>
    <script src="../addSelect/js/ydui.flexible.js"></script>
</head>
<body>
<section class="jq22-flexView">
	<header class="jq22-navBar jq22-navBar-fixed b-line">
<!--		<a href="javascript:;" class="jq22-navBar-item">-->
<!--			<i class="icon icon-return"></i>-->
<!--		</a>-->
		<div class="jq22-center">
			<span class="jq22-center-title">病人信息添加</span>
		</div>
		<a href="javascript:;" class="jq22-navBar-item">
			<i class="icon icon-sys"></i>
		</a>
	</header>
	<section class="jq22-scrollView">
<!--		<div class="jq22-auto-img">-->
<!--			<img src="images/head.png" alt="">-->
<!--		</div>-->
		<div class="jq22-auto-form">
			<div class="jq22-auto-box">
				<div class="jq22-palace">
					<a href="javascript:;" class="jq22-palace-grid">
						<div class="jq22-palace-grid-icon">
							<img src="../begin/images/item-001.png" alt="">
						</div>
						<div class="jq22-palace-grid-text">
							<h2>添加</h2>
						</div>
					</a>
					<a href="javascript:;" class="jq22-palace-grid">
						<div class="jq22-palace-grid-icon">
							<img src="../begin/images/item-002.png" alt="">
						</div>
						<div class="jq22-palace-grid-text">
							<h2>联系</h2>
						</div>
					</a>
					<a href="javascript:;" class="jq22-palace-grid">
						<div class="jq22-palace-grid-icon">
							<img src="../begin/images/item-003.png" alt="">
						</div>
						<div class="jq22-palace-grid-text">
							<h2>审核</h2>
						</div>
					</a>
					<a href="javascript:;" class="jq22-palace-grid">
						<div class="jq22-palace-grid-icon">
							<img src="../begin/images/item-004.png" alt="">
						</div>
						<div class="jq22-palace-grid-text">
							<h2>成功</h2>
						</div>
					</a>
				</div>
				<form action="" class="jq22-auto-inp">
					<div class="jq22-flex">
						<label>姓名</label>
						<div class="jq22-flex-box">
							<input type="text" name="name" placeholder="请输入姓名"/>
						</div>
					</div>
					<div class="jq22-flex">
						<label>性别</label>
						<div class="jq22-flex-box">
							<select id="hang" class="weui-select" name="sex">
								<option value="男" selected>男</option>
								<option value="女">女</option>
							</select>
						</div>
					</div>
                    <div class="jq22-flex">
                        <label>出生日期：</label>
                        <div class="jq22-flex-box">
                            <dl class="ss" style="float:left;width:234px;" id="birthday">
                                <input type="text" style="height:34px;float:left;width:234px;border-radius: 5px;" name="birthday" id="startTime"/>
                            </dl>
                        </div>
                    </div>
                    <div class="jq22-flex">
                        <label>身高/cm：</label>
                        <div class="jq22-flex-box">
                            <div class="jq22-flex-box">
                                <input type="number" class="height"  placeholder="请输入身高"/>
                            </div>
                        </div>
                    </div>
                    <div class="jq22-flex">
                        <label>体重/斤：</label>
                        <div class="jq22-flex-box">
                            <div class="jq22-flex-box">
                                <input type="number" class="weight" placeholder="请输入体重"/>
                            </div>
                        </div>
                    </div>
                    <div class="jq22-flex">
                        <label>地址：</label>
                        <div class="jq22-flex-box">
                            <div class="cell-item">
                                <div class="cell-right cell-arrow">
                                    <input type="text" class="cell-input" id="addr" readonly  value="湖南 长沙市 芙蓉区" placeholder="请选择收货地址">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="jq22-flex">
                        <label>详细住址：</label>
                        <div class="jq22-flex-box">
                            <dl class="ss" style="height:36px;float:left;width:234px;border-radius: 5px;" id="detail_address">
                                <input type="text" style="height:34px;float:left;width:234px;border-radius: 5px;" placeholder="请输入详细地址" name="detail_address"/>
                            </dl>
                        </div>
                    </div>
					<div class="jq22-flex">
						<label>电话号码：</label>
						<div class="jq22-flex-box">
                            <dl class="ss" style="height:36px;float:left;width:234px;border-radius: 5px;" id="phone">
                                <input type="number" style="height:34px;float:left;width:234px;border-radius: 5px;"  placeholder="请输入联系电话" name="phone"/>
                            </dl>
						</div>
					</div>
<!--					<div class="jq22-flex">-->
<!--						<label>密令</label>-->
<!--						<div class="jq22-flex-box">-->
<!--							<input type="text" id="password" autocomplete="off" placeholder="请输入密令">-->
<!--						</div>-->
<!--					</div>-->
					<button class="jq22-apply-btn" type="button" onclick="addOnes()">提交</button>

				</form>
			</div>
		</div>

	</section>
</section>
</body>
<script src="../addSelect/js/ydui.citys.js"></script>
<script src="../addSelect/js/ydui.js"></script>
<script src="../comment.js"></script>
<script>
    $(document).ready(function () {
        jeDate('#startTime', {
            minDate: '1990-01-01',
            isinitVal: true,
            format: 'YYYY-MM-DD',
            onClose: false,
            donefun:function(obj){
                // console.log(obj)
                var saliDate=obj.val.split("-");
                // console.log(saliDate)
                var riNum=0;
                var yueNum=0;
                var nianNum=saliDate[0];
                // console.log(saliDate[1]-1)
                // //判断月 同时判断年
                if(saliDate[1]-1<=0&&saliDate[2]=="01"){
                    yueNum=12;
                    riNum=31;
                    nianNum=nianNum;
                    // console.log(nianNum,yueNum,riNum)
                    $("#endTime").val(nianNum+"-"+yueNum+"-"+riNum)
                    return false;
                }else {
                    yueNum=saliDate[1];
                    nianNum=nianNum-0+1;
                }
                //当 日 是01 的时候要判断当前下一个月是否为31 还是30天  在判断一个是否为闰年  2月份是29 还是28
                if(saliDate[2]=="01"){
                    switch(saliDate[1]-1){
                        case 1:
                        case 3:
                        case 5:
                        case 7:
                        case 8:
                        case 10:
                        case 0://0就是12月  因为是只有点击的是2019-01-01  才会是2018-12-31
                            riNum=31;
                            yueNum="0"+(saliDate[1]-1);
                            break;
                        case 4:
                        case 6:
                        case 9:
                        case 11:
                            riNum=30;
                            yueNum="0"+(saliDate[1]-1);
                            break;
                    }
                    if(saliDate[1]-1==2){
                        yueNum="0"+(saliDate[1]-1);
                        //判断是否为闰年
                        if(isLeap(saliDate[0])==1){
                            riNum=29;
                        }else{
                            riNum=28;
                        }
                    }
                }else{
                    if(saliDate[2]-1<=9){
                        riNum="0"+(saliDate[2]-1);
                    }else{
                        riNum=saliDate[2]-1;
                    }
                }
                // $("#endTime").val(nianNum+"-"+yueNum+"-"+riNum)
                // console.log(nianNum,yueNum,riNum)
            }
        });
        // jeDate('#endTime', {
        //     minDate: '1990-01-01',
        //     isinitVal: true,
        //     format: 'YYYY-MM-DD',
        //     onClose: false
        // });

        //判断是否为闰年  若为闰年，返回1，反之则返回0
        function isLeap(year) {
            if((year%4==0 && year%100!=0)||(year%400==0)){
                return 1;
            }
            return 0;
        }
    })
	function isPoneAvailable(phone) {
		var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
		if (!myreg.test(phone)) {
			return false;
		} else {
			return true;
		}
	}
    $.fn.serializeJson=function(){
        var serializeObj={};
        var array=this.serializeArray();
        array.push({"name":"name","value":document.getElementsByName("name")[0].value+""});
        array.push({"name":"sex","value":$("#hang").val()+""});
        array.push({"name":"birthday","value":document.getElementsByName("birthday")[0].value+""});
        array.push({"name":"height","value":$(".height").val()+""});
        array.push({"name":"weight","value":$(".weight").val()+""});
        if(document.getElementsByName("detail_address")[0].value!==""||document.getElementsByName("detail_address")[0].value!=null){
            array.push({"name":"address","value":$("#addr").val()+"-"+document.getElementsByName("detail_address")[0].value});
        }else {
            array.push({"name":"address","value":$("#addr").val()});
        }
        array.push({"name":"phone","value":document.getElementsByName("phone")[0].value+""});

        var str=this.serialize();
        $(array).each(function(){
            if(serializeObj[this.name]){
                if($.isArray(serializeObj[this.name])){
                    serializeObj[this.name].push(this.value);
                }else{
                    serializeObj[this.name]=[serializeObj[this.name],this.value];
                }
            }else{
                serializeObj[this.name]=this.value;
            }
        });
        return serializeObj;
    };
    function addOnes() {
        if((document.getElementsByName("name")[0].value==""|| document.getElementsByName("name")[0].value==null)
            ||(document.getElementsByName("birthday")[0].value==""|| document.getElementsByName("birthday")[0].value==null)
            ||(document.getElementsByName("phone")[0].value==""|| document.getElementsByName("phone")[0].value==null)
				||($("#addr").val()==""|| $("#addr").val()==null)){
            alert("信息未填完")
        } else if(($(".height").val()=="0"|| $(".height").val()==null||$(".height").val()=="")
        ||($(".weight").val()=="0"|| $(".weight").val()==null||$(".weight").val()=="")){
            alert("请检查身高/体重信息")
        } else if(!isPoneAvailable(document.getElementsByName("phone")[0].value)){
			alert("请输入正确的手机号")
		}else{
            $.ajax({
                //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: MyServer+"h5/patient_info_from" ,//url
				headers: {
					"Authorization" : sessionStorage.getItem("Authorization"),
				},
                data: $('#froms').serializeJson(),//获取表单数据
                success: function (result) {
                    if (result.code === 200) {
                        alert("提交成功");
                        history.back();
                    }else if(result.code===401){
                        alert("您未登陆")
                    }else if(result.code===405){
                        alert(result.message);
                    }else if(result.code===406){
                        alert(result.message);
                    }else{
                        alert("提交失败");
                    };
                },
                error : function() {
                    alert("服务器开小差了！")
                }
            });
        }

    }
    /**
     * 设置默认值
     */
    !function () {
        var $target = $('#addr');

        $target.citySelect({
            provance: '湖南',
            city: '长沙市',
            area: '芙蓉区'
        });

        $target.on('click', function (event) {
            event.stopPropagation();
            $target.citySelect('open');
        });

        $target.on('done.ydui.cityselect', function (ret) {
            $(this).val(ret.provance + ' ' + ret.city + ' ' + ret.area);
        });
    }();
</script>
</html>
